<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<html>
<head>
    <title>图书批次</title>
    <meta name="decorator" content="default"/>
    <script src="${ctxStatic}/lodop/LodopFuncs.js" type="text/javascript"></script>
    <script type="text/javascript">
        function page(n, s) {
            $("#pageNo").val(n);
            $("#pageSize").val(s);
            $("#searchForm").submit();
            return false;
        }
        function btnClear() {
            $("#searchForm").find("input[type='text']").each(function () {
                $(this).val("");
            });
        }

        function chechRadio(rowId)
        {
            var temprowid = "radio"+rowId;
            var bacthid="#batchId"+rowId;
            document.getElementById(temprowid).checked = true;
            $("#workBacthid").val($(bacthid).val());

        }
        //设置工作验收批次
        function setWorkBatch(){
            var workbatchid = $("#workBacthid").val();
            var workBacthNumber ="";
            if(workbatchid==""){
                alert("请选择批次编号！")
                return;
            } else {
                workBacthNumber = $('input[name="radioitem"]').filter(':checked').val();
                if(confirm("确认设置验收批次【"+workBacthNumber+"】为工作验收批次？")){
                    window.location.href="${ctx}/book/purchase/setworkbatch?workbatchid="+workbatchid;
                } else {

                }

            }
        }
        //将验收批次关闭
        function confirmBatch(){
            var workbatchid = $("#workBacthid").val();
            var workBacthNumber ="";
            if(workbatchid==""){
                alert("请选择批次编号！")
                return;
            } else {
                workBacthNumber = $('input[name="radioitem"]').filter(':checked').val();
                if(confirm("确认关闭验收批次【"+workBacthNumber+"】？")){
                    window.location.href="${ctx}/book/purchase/confirmBatch?workbatchid="+workbatchid;
                } else {

                }

            }
        }
        function checkPurcharse(batchNumber){
            $("#workpatchnumber").html(batchNumber);
        }
        function deleteBatch(batchId){
            if(confirm("您确认要删除当前批次吗？")){
                $.ajax({
                    type: "POST",
                    url: "${ctx}/book/purchase/delete",
                    data: {batchId: batchId},
                    dataType: "json",
                    success: function (data) {
                        if (data.code == "0001") {
                            top.$.jBox.info(data.msg, '提示', {
                                closed: function () {
                                    window.location.href = "${ctx}/book/purchase/list";
                                }
                            });
                            top.$('.jbox-body .jbox-icon').css('top', '55px');

                        } else {
                            alertx("删除批次失败！");
                        }
                    }
                });
            }

        }
    </script>
</head>
<body>
<ul class="nav nav-tabs">
    <li class="active"><a href="${ctx}/book/purchase/list">采购批次</a></li>
    <li><a href="${ctx}/book/purchase/form">新增批次</a></li>
</ul>
<br/>
<div>
    当前工作验收批次：【<label style="color: red;font-size: 24px;" id="workpatchnumber">${currentworkbatch.batchNumber}</label>】
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input id="setWorkBatch" class="btn btn-primary" type="button" onclick="setWorkBatch();" value="设置工作验收批次"/>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input id="confirmBatch" class="btn btn-primary" type="button" onclick="confirmBatch();" value="关闭验收批次"/>
</div>
<form:form id="searchForm" modelAttribute="bkPurchaseBatch" action="${ctx}/book/purchase/list" method="post" class="breadcrumb form-search">
    <input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
    <input id="workBacthid" name="workBacthid" type="hidden" value=""/>
    <input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
    <label>批次编号：</label>
    <form:input path="batchNumber" htmlEscape="false" maxlength="20" class="input-medium"/>
    <%--<label>开始日期：</label>--%>
    <%--<form:input id="beginDate" path="beginDate" htmlEscape="false" readonly="true" maxlength="20"--%>
                <%--class="input-medium Wdate"--%>
                <%--pattern="yyyy-MM-dd"--%>
                <%--onclick="WdatePicker({dateFmt:'yyyy-MM-dd',maxDate:'#F{$dp.$D(endDate)}'})"/>--%>

    <%--<label>结束日期：</label>--%>
    <%--<form:input id="endDate" path="endDate" htmlEscape="false" readonly="true" maxlength="20"--%>
                <%--class="input-medium Wdate"--%>
                <%--pattern="yyyy-MM-dd"--%>
                <%--onclick="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(beginDate)}'})"/>--%>

    <input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/>&nbsp;&nbsp;
    <a href="javascript:void(0)" onclick="btnClear()" class="btn">清空条件</a>&nbsp;

</form:form>
<sys:message content="${message}"/>
<table id="contentTable" class="table table-striped table-bordered table-condensed">
    <thead>
    <tr>
        <th width="50">选择</th>
        <th width="180">批次编号</th>
        <th width="180">发票号</th>

        <%--<th width="120">计划日期</th>--%>
        <th width="80">创建日期</th>
        <%--<th>码洋</th>--%>
        <th  width="50">状态</th>
        <th width="180">备注</th>
        <th width="120">操作</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${page.list}" var="info" varStatus="status">
        <tr id="tritem${status.count}" onclick="chechRadio(${status.count})">
            <input id="batchId${status.count}" name="batchId${status.count}" type="hidden" value="${info.batchId}">
            <td><input id="radio${status.count}" name="radioitem" type="radio" value="${info.batchNumber}" onclick="checkPurcharse('${info.batchNumber}')"></td>
            <td>${info.batchNumber}</td>
            <td>${info.invoice}</td>
            <%--<td><fmt:formatDate value="${info.planDate}" type="date"/></td>--%>
            <td><fmt:formatDate value="${info.batchDate}" type="date"/></td>
                <%--<td>${info.fixedPrice}</td>
                <td>${info.discountedPrice}</td>--%>
            <td>
                <c:if test="${info.status eq 'check'}">
                    待验收
                </c:if>
                <c:if test="${info.status eq 'work'}">
                    验收中
                </c:if>
                <c:if test="${info.status eq 'confirm'}">
                    验收结束
                </c:if>
            </td>
            <td>
                <script>document.write(decodeURI('${info.remarks}'))</script>
            </td>
            <td>
                <shiro:hasPermission name="book:purchase:delete">
                    <a href="javascript:void(0);" onclick="deleteBatch(${info.batchId})">删除</a>
                </shiro:hasPermission>
                <shiro:hasPermission name="book:purchase:save">
                    <a href="${ctx}/book/purchase/gotoEdit?batchId=${info.batchId}">
                        <c:if test="${info.status eq 'work'}">
                            登到
                        </c:if>
                        <%--<c:if test="${info.status eq 'ok'}">
                            取消登到
                        </c:if>--%>
                    </a>
                </shiro:hasPermission>

                <%--<shiro:hasPermission name="book:store:print">
                    <c:if test="${info.status eq 'ok'}">
                        <a href="javascript:void(0);" onclick="printPreview('${info.batchId}')">
                            打印书标
                        </a>
                    </c:if>
                </shiro:hasPermission>--%>

                <a href="${ctx}/book/purchase/batch?batchId=${info.batchId}">详情</a>
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>
<div class="pagination">${page}</div>

<object id="LODOP" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width=0 height=0>
    <param name="Border" value="1">
    <param name="Color" value="white">
    <embed id="LODOP_EM" TYPE="application/x-print-lodop" width=0 height=0 border=0 Color="white"
           PLUGINSPAGE="install_lodop.exe">
</object>

<script type="text/javascript">

    /**
     *  打印预览
     */
    //声明为全局变量
    var LODOP;
    function printPreview(batchId) {
        LODOP = getLodop(document.getElementById('LODOP'), document.getElementById('LODOP_EM'));
        LODOP.PRINT_INIT("打印");
        LODOP.SET_PRINT_PAGESIZE(1, 0, 0, "A4");
        var y = -1;
        var x = 0;

        $.ajax({
            type: "POST",
            url: "${ctx}/book/store/print",
            data: {batchId: batchId},
            dataType: "json",
            success: function (bookstores) {
                for (var i = 0; i < bookstores.length; i++) {
                    var store = bookstores[i];
                    if (i % 2 == 0) {
                        y++;
                        x = 0;
                    }
                    var banid = store.banid;
                    var bar = "<div style='background-color:#ffffff;font-size: 18px;text-align: center;'>" +
                            "<div style='height:25px;'>" + store.classcode + "</div>" +
                            "<div style='height:25px;'>" + store.place + "</div>" +
                            "<div style='height:16px;'>" + banid + "</div>" +
                            "</div>";
                    /*// 打印条形码
                    LODOP.ADD_PRINT_BARCODE(25 + y * 112, 34 + x * 370, 159, 70, "code39", banid);*/
                    // 打印 索书号和分类
                    LODOP.ADD_PRINT_HTM(25 + y * 112, 34 + x * 370, 159, 70, bar);
                    x++;
                }
                LODOP.PRINT_DESIGN();
                LODOP.SHOW_CHART();
            }
        });
    }
</script>

</body>
</html>